﻿using System.Collections.Generic;
using System.ComponentModel;

namespace WPF_CAD.Model
{
    public abstract class FigureBase : IFigure, INotifyPropertyChanged
    {
        private IList<IPoint> _pointsCollection; 
        public IList<IPoint> PointsCollection 
        {
            get { return _pointsCollection; }
            set 
            { 
                _pointsCollection = value;
                InvokePropertyChanged("PointsCollection");
            }
        }

        public DrawStatus DrawStatus { get; set; }

        public IPoint InitialPoint
        {
            get { return PointsCollection[0]; }
        }

        public IPoint FinalPoint
        {
            get 
            { 
                return  PointsCollection.Count > 1? PointsCollection[PointsCollection.Count - 1]: InitialPoint; }
        }

        protected FigureBase()
        {
            _pointsCollection = new List<IPoint>();
            DrawStatus = DrawStatus.Incompleted;
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void InvokePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
